home *** CD-ROM | disk | FTP | other *** search
- /*
- * Two-column LDEF code resource
- *
- * looks for a comma in the text of each cell and draws
- * the text that follows the comma half-way across the cell
- *
- * so a cell containing the text
- * +--------------+
- * | abc,def |
- * +--------------+
- * will instead appear as
- * +--------------+
- * | abc def |
- * +--------------+
- *
- * To see this LDEF in action, paste it into the ModalList
- * sample program and recompile the program so that the LNew call uses
- * the definition procedure 128 rather than 0
- *
- * Greg Robbins 8/93
- *
- * Based on Steve Falkenburg's SICN LDEF
- */
-
- #include <Lists.h>
- #include <SysEqu.h>
- #include <ToolUtils.h>
- #include <String.h>
-
- /* constants for spacing */
-
- #define kLeftOffset 2
- #define kTopOffset 0
-
-
- /* main LDEF entry point */
-
- pascal void main(short lMessage,Boolean lSelect,Rect *lRect,Cell lCell,
- short lDataOffset,short lDataLen,ListHandle lHandle)
- {
- FontInfo fontInfo; /* font information (ascent/descent/etc) */
- ListPtr listPtr; /* pointer to store dereferenced list */
- SignedByte hStateList,hStateCells; /* state variables for HGetState/SetState */
- Ptr cellData; /* points to start of cell data for list */
- short leftDraw,topDraw; /* left/top offsets from topleft of cell */
- short halfwayLeftDraw; /* half way across from left of cell */
- short substringLen; /* number of characters before comma */
- Ptr commaPtr; /* substring beginning at comma */
- Point currPenPt; /* current pen location */
- Rect fullCellRect; /* unclipped size of cell */
-
- /* lock and dereference list mgr handles */
-
- hStateList = HGetState((Handle) lHandle);
- HLock((Handle) lHandle);
- listPtr = *lHandle;
-
- hStateCells = HGetState(listPtr->cells);
- HLock(listPtr->cells);
-
- cellData = *(listPtr->cells);
-
- /* get the size of the cells (since lRect may be clipped) */
-
- LRect(&fullCellRect, lCell, lHandle);
-
- switch (lMessage) {
- case lInitMsg:
- /* we don't need any initialization */
- break;
-
- case lDrawMsg:
- EraseRect(lRect);
-
- if (lDataLen > 0) {
-
- /* determine starting point for drawing */
-
- leftDraw = lRect->left + listPtr->indent.h + kLeftOffset;
- topDraw = lRect->top + listPtr->indent.v + kTopOffset;
-
- /* move to the text location */
- GetFontInfo(&fontInfo);
- MoveTo(leftDraw, topDraw + fontInfo.ascent);
-
- /* if there's a comma, only draw the characters up to the comma
- and then move the data offset and length variables to
- point to the rest of the string following that comma */
-
- /* look for a comma, using memchr from the ANSI libraries (yech) */
- commaPtr = memchr(cellData + lDataOffset, ',', lDataLen);
-
- if (commaPtr != nil) {
-
- /* draw the substring preceding the comma */
- substringLen = (short) (commaPtr - (cellData + lDataOffset));
- DrawText(cellData, lDataOffset, substringLen);
-
- /* move the offset to skip the first substring and comma */
- lDataOffset += substringLen + 1;
- lDataLen -= (substringLen + 1);
-
- /* move to half way across the cell unless the pen
- is already to the right of that point */
-
- halfwayLeftDraw = (fullCellRect.right + leftDraw) / 2;
- GetPen(&currPenPt);
- if (currPenPt.h < halfwayLeftDraw)
- MoveTo(halfwayLeftDraw, topDraw+fontInfo.ascent);
- }
-
- /* draw all remaining characters in the cell */
- DrawText(cellData, lDataOffset, lDataLen);
-
- }
-
- if (!lSelect)
- break;
-
- case lHiliteMsg:
- /* clearing the HiliteMode bit forces the next Invert to really
- be a "hilite" mode inversion */
-
- BitClr((Ptr)HiliteMode,pHiliteBit);
- InvertRect(lRect);
- break;
-
- case lCloseMsg:
- break;
- }
-
- /* restore the handles to their original states */
- HSetState(listPtr->cells,hStateCells);
- HSetState((Handle) lHandle,hStateList);
- }
-
-